package priv.project.controller.web;

import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import priv.project.pojo.Rate;
import priv.project.pojo.ResultMessage;
import priv.project.pojo.ScenicSpot;
import priv.project.pojo.User;
import priv.project.service.RateService;
import priv.project.service.ScenicSpotService;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/web/rate")
@AllArgsConstructor
public class WebRateController {
    private RateService rateService;
//    查询评分记录
    @GetMapping("/getRate")
    public ResultMessage getOne(Rate rate){
        try{
            return new ResultMessage(200,"查询成功！",rateService.getOne(rate));
        }catch (Exception e){
            e.printStackTrace();
            return new ResultMessage(500, "查询失败！");
        }
    }
    @GetMapping("/getUnRate")
    public ResultMessage getUnOne(Rate rate){
        try{
            return new ResultMessage(200,"查询成功！",rateService.getUnOne(rate));
        }catch (Exception e){
            e.printStackTrace();
            return new ResultMessage(500, "查询失败！");
        }
    }
//更新评分记录
    @PostMapping("/updateRate")
    public ResultMessage updateInfo(@RequestBody Rate entity, HttpSession session){
        try{
//            User user =(User) session.getAttribute("webUser");
//            ScenicSpot scenicSpot =(ScenicSpot) session.getAttribute("obj");
            System.out.println("********"+entity);
            if(entity.getUserId()==0)
                return new ResultMessage(500,"更新失败");
            if(entity.getRateOne()!=0&&entity.getRateTwo()!=0&& entity.getRateThree()!=0&&entity.getRateFour()!=0&& entity.getRateFive()!=0&&entity.getRateSix()!=0)
                entity.setIsRate(true);
//            entity.setScenicId(scenicSpot.getId());
            System.out.println("------"+entity);
            return new ResultMessage(200,"更新成功！",rateService.update(entity));
        }catch (Exception e){
            e.printStackTrace();
            return new ResultMessage(500, "更新失败！");
        }
    }
}
